/*
* jlb
*/
package com.jlb.my.ctrl;

import com.alibaba.fastjson.JSON;
import com.jlb.core.entity.BeanRet;
import com.jlb.core.entity.Page;
import com.jlb.core.tools.redis.RedisUtils;
import com.jlb.my.entity.MyGroup;
import com.jlb.my.service.MyGroupSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * 我与团队关系 控制器
 *
 * @author jlb
 */
@RestController
@RequestMapping("/myGroup")
@Slf4j
@Api(value = "我与团队关系控制器", description = "我与团队关系控制器")
public class MyGroupCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private MyGroupSV myGroupSV;

    /**
     * 查询MyGroup一个详情信息
     *
     * @param id
     * @param userCode 用户编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询MyGroup一个详情信息", notes = "查询MyGroup一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "query"),
            @ApiImplicitParam(name = "userCode", value = "用户编码", dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public BeanRet load(java.lang.Long id, java.lang.String userCode) {
        if (id == null) {
            return null;
        }
        if (userCode == null) {
            return null;
        }
        MyGroup myGroup = myGroupSV.load(id, userCode);
        log.info(JSON.toJSONString(myGroup));
        return BeanRet.create(true, "查询成功", myGroup);
    }


    /**
     * 根据条件id查询MyGroup一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询MyGroup一个详情信息", notes = "查询MyGroup一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public BeanRet loadById(@PathVariable java.lang.Long id) {
        if (id == null) {
            return null;
        }
        MyGroup myGroup = myGroupSV.loadById(id);
        log.info(JSON.toJSONString(myGroup));
        return BeanRet.create(true, "查询成功", myGroup);
    }

    /**
     * 根据条件userCode查询MyGroup一个详情信息
     *
     * @param userCode 用户编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询MyGroup一个详情信息", notes = "查询MyGroup一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userCode", value = "用户编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/userCode/{userCode}")
    @ResponseBody
    public BeanRet loadByUserCode(@PathVariable java.lang.String userCode) {
        if (userCode == null) {
            return null;
        }
        MyGroup myGroup = myGroupSV.loadByUserCode(userCode);
        log.info(JSON.toJSONString(myGroup));
        return BeanRet.create(true, "查询成功", myGroup);
    }


    /**
     * 查询MyGroup信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询MyGroup信息集合", notes = "查询MyGroup信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
    })
    @GetMapping(value = "/list")
    @ResponseBody
    public BeanRet list(@ApiIgnore MyGroup myGroup, Integer curPage, Integer pageSize) {
        Page<MyGroup> page = new Page<MyGroup>(pageSize, curPage);
        List<MyGroup> myGroups = myGroupSV.list(myGroup, page.genRowStart(), page.getPageSize());
        page.setVoList(myGroups);
        int total = myGroupSV.count(myGroup);
        page.setTotalRow(total);

        return BeanRet.create(true, "查询成功", page);

    }


    /**
     * 查询MyGroup信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询MyGroup信息集合", notes = "查询MyGroup信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "userCode", value = "用户编码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public BeanRet listByPk(java.lang.Long id, java.lang.String userCode, Integer curPage, Integer pageSize) {
        Page<MyGroup> page = new Page<MyGroup>(pageSize, curPage);
        List<MyGroup> myGroups = myGroupSV.list(id, userCode, page.genRowStart(), page.getPageSize());
        page.setVoList(myGroups);
        int total = myGroupSV.count(id, userCode);
        page.setTotalRow(total);

        return BeanRet.create(true, "查询成功", page);
    }

    /**
     * 统计MyGroup信息数量根据主键
     *
     * @return 总条数
     */
    @ApiOperation(value = " 统计MyGroup信息数量根据主键", notes = " 统计MyGroup信息数量根据主键")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "userCode", value = "用户编码", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(java.lang.Long id, java.lang.String userCode) {
        return myGroupSV.count(id, userCode);
    }

    /**
     * 统计MyGroup信息数量
     *
     * @return 总条数
     */
    @ApiOperation(value = "统计MyGroup信息数量", notes = "统计MyGroup信息数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "userCode", value = "用户编码", paramType = "query"),
            @ApiImplicitParam(name = "subUserCode", value = "下级用户编码", paramType = "query"),
            @ApiImplicitParam(name = "subLevel", value = "下级层级", paramType = "query"),
            @ApiImplicitParam(name = "rate", value = "动态收益百分比", paramType = "query"),
            @ApiImplicitParam(name = "oreNum", value = "动态收益矿石", paramType = "query")
    })
    @GetMapping(value = "/count")
    @ResponseBody
    public Integer count(@ApiIgnore MyGroup myGroup) {
        if (myGroup == null) {
            return myGroupSV.count(new HashMap());
        } else {
            return myGroupSV.count(myGroup);
        }
    }


    /**
     * 创建MyGroup
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建MyGroup", notes = "创建MyGroup")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "subUserCode", value = "下级用户编码", paramType = "query"),
            @ApiImplicitParam(name = "subLevel", value = "下级层级", paramType = "query"),
            @ApiImplicitParam(name = "rate", value = "动态收益百分比", paramType = "query"),
            @ApiImplicitParam(name = "oreNum", value = "动态收益矿石", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public BeanRet build(@ApiIgnore MyGroup myGroup) {
        myGroupSV.save(myGroup);
        return BeanRet.create(true, "创建成功", myGroup);
    }


    /**
     * 修改MyGroup
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改MyGroup", notes = "修改MyGroup")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "userCode", value = "用户编码", paramType = "query"),
            @ApiImplicitParam(name = "subUserCode", value = "下级用户编码", paramType = "query"),
            @ApiImplicitParam(name = "subLevel", value = "下级层级", paramType = "query"),
            @ApiImplicitParam(name = "rate", value = "动态收益百分比", paramType = "query"),
            @ApiImplicitParam(name = "oreNum", value = "动态收益矿石", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public BeanRet modify(@ApiIgnore MyGroup myGroup) {
        myGroupSV.modify(myGroup);
        return BeanRet.create(true, "修改成功", myGroup);
    }

    /**
     * 删除MyGroup
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除MyGroup", notes = "删除MyGroup")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "userCode", value = "用户编码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(java.lang.Long id, java.lang.String userCode) {
        myGroupSV.delete(id, userCode);
        return BeanRet.create(true, "删除MyGroup成功");
    }

}
